<template>
  <div id="app">
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <template v-for="item in menuItems">
        <el-menu-item v-if="!item.children" :index="item.index" :key="item.index">
          {{ item.label }}
        </el-menu-item>
        <el-submenu v-else :index="item.index" :key="item.index">
          <template slot="title">{{ item.label }}</template>
          <el-menu-item v-for="child in item.children" :index="child.index" :key="child.index">
            {{ child.label }}
          </el-menu-item>
        </el-submenu>
      </template>
    </el-menu>
    <router-view />
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: '1',
      menuItems: [
        { index: '1', label: '柱状图', path: '/' },
        { index: '2', label: '折线图', path: '/lineChart' },
      ]
    };
  },
  methods: {
    handleSelect(key) {
      const clickItem = this.menuItems.find(item => item.index === key)
      this.$router.push({
        path: clickItem.path
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
